package domein;

import java.net.*;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * 
 * @author rensbonnez
 * This class will hold al the Datagram packets.
 *
 */

public class DatagramPacketQueu 
{
	private ArrayBlockingQueue<DatagramPacket> datagramQueu;
	
	public DatagramPacketQueu(int queuSize)
	{
		datagramQueu = new ArrayBlockingQueue<DatagramPacket>(queuSize);
	}
	
	/**
	 * Method add an DatagramPacket on the queu
	 * @param DatagramPacket packet
	 */
	public void addPacket(DatagramPacket packet)
	{
		try 
		{
			datagramQueu.put(packet);
		} 
		catch (InterruptedException e) 
		{
			e.printStackTrace();
		}
	}
	
	/**
	 * Method get the first packet on queu and remove it from the queu
	 * @return DatagramPacket
	 */
	public DatagramPacket getPacket()
	{
		try 
		{
			DatagramPacket packet = datagramQueu.take();
			return packet;
		} 
		catch (InterruptedException e) 
		{
			e.printStackTrace();
			return null;
		}
	}
}
